//
//  Easchview.m
//  oc微博
//
//  Created by 代亚洲 on 16/4/18.
//  Copyright © 2016年 itcast. All rights reserved.
//

#import "Easchview.h"
#import "UIView+JACKFrameExt.h"


@interface Easchview ()
//输入框
@property (weak, nonatomic) IBOutlet UITextField *tx_easchview;
//取消按钮
@property (weak, nonatomic) IBOutlet UIButton *bt_cancle;
//输入框偏移量
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *tx_constraint;
//输入框的图片
@property(nonatomic,strong)UIImageView *eachiamgeview;

@end

@implementation Easchview

//加载xib
+(instancetype)nationalFlagWithXib{
    return [[[NSBundle mainBundle] loadNibNamed:@"Easchview" owner:nil options:nil] lastObject];
}
// 从xib里面唤醒
// 里面的子控件全部连线完毕 会调用这个方法
-(void)awakeFromNib{
    
//    设置txfied的属性
    [self.tx_easchview setBorderStyle:UITextBorderStyleLine];
    self.tx_easchview.layer.borderWidth = 3;
    self.tx_easchview.layer.borderColor = [UIColor redColor].CGColor;
//    圆角弧度
    self.tx_easchview.layer.cornerRadius =10;
    self.tx_easchview.layer.backgroundColor = [UIColor blueColor].CGColor;
    
    self.eachiamgeview.w = self.frame.size.height;
    self.eachiamgeview.h = self.frame.size.height;
    self.tx_easchview.leftView = self.eachiamgeview;
    self.tx_easchview.leftViewMode = UITextFieldViewModeAlways;
    
}

//懒加载图片
-(UIImageView *)eachiamgeview{
    if (_eachiamgeview==nil) {
//        设置图片
        _eachiamgeview = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"searchbar_textfield_search_icon"]];
//        设置图片显示模式
        _eachiamgeview.contentMode = UIViewContentModeCenter;
        
    }
    return _eachiamgeview ;
}

//点击搜索框
- (IBAction)didclickTXF:(UITextField *)sender {
    
//    更改约束
    self.tx_constraint.constant = self.bt_cancle.frame.size.width+10;
//    NSLog(@"%f",self.bt_cancle.frame.size.width+10);
    
//        设置动画       动画时间
    [UIView animateWithDuration:0.25 animations:^{
//  因为不满足调用layoutsubviews  所以调用self.layoutIfNeeded() 他会自动调用layoutsubviews
        [self layoutIfNeeded];
        
    }];
    
    
}
//点击取消按钮
- (IBAction)didclickcanclebutton:(UIButton *)sender {
//    移除输入框第一响应者
    [self.tx_easchview resignFirstResponder];
    
//    更改约束
    self.tx_constraint.constant = 0;
    NSLog(@"%f",self.bt_cancle.frame.size.width+10);
    
//        设置动画       动画时间
    [UIView animateWithDuration:0.25 animations:^{
        //  因为不满足调用layoutsubviews  所以调用self.layoutIfNeeded() 他会自动调用layoutsubviews
        [self layoutIfNeeded];
        
    }];
}



@end
